﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.Security;

namespace Sueetie.Core
{
    public class SueetieContext
    {

        private static SueetieContext _currentInstance = new SueetieContext();
        public static SueetieContext Current
        {
            get
            {
                Page currentPage = HttpContext.Current.Handler as Page;
                if (currentPage == null)
                {
                    return _currentInstance;
                }
                // save the SueetieContext to base classes
                return (currentPage.Items["CurrentPageContext"] ?? (currentPage.Items["CurrentPageContext"] = new SueetieContext())) as SueetieContext;
            }
        }

        public bool IsAnonymousUser
        {
            get
            {
                MembershipUser user = Membership.GetUser();
                if (user != null)
                    return false;
                else
                    return true;
            }
        }
        public SueetieUser User
        {
            get
            {
                if (!IsAnonymousUser)
                {
                    MembershipUser user = Membership.GetUser();
                    int userID = SueetieUsers.GetUserID(user.UserName);
                    return SueetieUsers.GetUser(userID);
                }
                else
                    return SueetieUsers.GetAnonymousUser();

            }
        }

        public SueetieUserProfile UserProfile
        {
            get
            {
                if (!IsAnonymousUser)
                {

                    int userID = SueetieUsers.GetUserID(this.User.UserName);
                    return SueetieUsers.GetSueetieUserProfile(userID);
                }
                else
                    return SueetieUsers.GetAnonymousUserProfile();
            }
        }
        public QueryStringIDHelper QueryIDs { get; set; }


    }
}
